/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package hu.intersoft.sandbox.web.admin;

import hu.intersoft.sandbox.ejb.entity.News;
import hu.intersoft.sandbox.ejb.logic.SandboxManagerRemote;
import java.util.Date;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
 *
 * @author ntb
 */
public class NewsRegst {

    private SandboxManagerRemote manager = null;
    private Context ctx = null;

    public NewsRegst() throws NamingException {
        ctx = new InitialContext();
        manager = (SandboxManagerRemote) ctx.lookup("SandboxManager/remote");
    }

    private void clearForm() {
        newsContent = newsHeader = newsTag = "";
    }

    public String saveNews() {
        News news = new News();
        news.setHeader(getNewsHeader());
        news.setTag(getNewsTag());
        news.setDescription(getNewsContent());
        news.setCreated(new Date());
        manager.addNews(news);

        clearForm();
        return "root";
    }
    
    private String newsContent;
    private String newsHeader;
    private String newsTag;

    public String getNewsHeader() {
        return newsHeader;
    }

    public void setNewsHeader(String newsHeader) {
        this.newsHeader = newsHeader;
    }

    public String getNewsTag() {
        return newsTag;
    }

    public void setNewsTag(String newsTag) {
        this.newsTag = newsTag;
    }

    public String getNewsContent() {
        return newsContent;
    }

    public void setNewsContent(String newsContent) {
        this.newsContent = newsContent;
    }
}
